const { exercisesModel } = require('../models/exercisesModel')
// 获取所有的题

module.exports.getExercises = async function (req, res, next) {
    // 接受前端发送的数据
    const result = await exercisesModel.find()
    // console.log("获取到的数据", result);
    if (result.length > 0) {
        res.send({
            message: "获取成功",
            code: 1,
            result
        });
    } else {
        res.send({
            message: "获取失败",
            code: 0
        });
    }
    // 返回数据给前端

}

module.exports.getExercisesByid = async function (req, res, next) {
    // 接受前端发送的数据wf
    const data = req.body

    const result = await exercisesModel.find({ pointId: data.pointId })

    if (result.length > 0) {
        res.send({
            message: "获取成功",
            code: 1,
            result
        });
    } else {
        res.send({
            message: "获取失败",
            code: 0
        });
    }
}

//获取一道题
module.exports.getOneTitle = async function (req, res, next) {
    //接受前端发送的数据
    const data = req.body;
    // console.log(data);
    const result = await exercisesModel.find(data);
    // console.log(result);
    if (result) {
        res.send({
            code: 1,
            message: '题目信息获取成功',
            result: result

        });
    } else {
        res.send({
            code: 0,
            message: '题目信息获取失败'
        })
    }

};